package cn.tedu.toa.management.sys.mapper;

import cn.tedu.toa.management.sys.entity.SysMenus;
import cn.tedu.toa.management.sys.vo.MenuNodeVo;
import cn.tedu.toa.management.sys.vo.MenuVo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Set;

/**
 * <p>
 * 资源管理 Mapper 接口
 * </p>
 *
 * @author huaqian
 * @since 2021-09-09
 */
public interface SysMenusMapper extends BaseMapper<SysMenus> {
    @Select("SELECT " +
            "m1.id,m1.name,m1.url,m1.type,m1.sort,m1.parentId," +
            "m2.name as parentName,m1.permission  " +
            "FROM sys_menus m1 " +
            "LEFT JOIN sys_menus m2 " +
            "ON m1.parentId=m2.id")
    List<MenuVo> selectMenuList();

    @Select("select count(*) from sys_menus where parentId=#{menuId}")
    Integer selectSubMenuCountByMenuId(Integer menuId);

    @Select("select count(*) from sys_role_menus where menu_id=#{menuId}")
    Integer selectRoleMenuCoutnByMenuId(Integer menuId);

    @Select("select id,name,parentId from sys_menus ")
    List<MenuNodeVo> selectMenuNodes();

    @Select("SELECT " +
            "m1.id,m1.name,m1.url,m1.type,m1.sort,m1.parentId," +
            "m2.name as parentName,m1.permission  " +
            "FROM sys_menus m1 " +
            "LEFT JOIN sys_menus m2 " +
            "ON m1.parentId=m2.id where m1.id=#{id}")
    MenuVo selectMenuVo(Integer id);


    int selectCountByMenuIds(@Param("menuIds") Integer[] menuIds);

    Set<String> selectPermissionsByMenuIds(@Param("menuIds") Integer[] menuIds);
}
